﻿Imports Trinkets.Core
Imports Trinkets.UserInterfaceGenerator

Module ToDoExample

    <Table(singularCaption:="Task", multipleCaption:="Tasks")> _
    Public Class Task
        Inherits BaseEntity

        <Field()> <PrimaryKey()> Public Property TaskID As Integer
        <Field()> Public Property Title As String
        <Field(displayName:="Important?")> Public Property Important As Boolean
        <Field(displayName:="Urgent?")> Public Property Urgent As Boolean
        <Field(isDisplayColumn:=False)> Public Property Notes As String
        <Field(displayName:="Date Completed")> Public Property CompletedDate As DateTime

        Public Overrides Function ToString() As String
            Return Title
        End Function

        Protected Overrides Sub Validate(ByVal errors As List(Of String), ByVal warnings As List(Of String))
            If String.IsNullOrEmpty(Title) Then errors.Add("The title must be specified.")
            If CompletedDate > Now Then warnings.Add("The date completed is in the future.")
        End Sub

    End Class

    Sub Main()

        ' Compile and open the database (one is created if necessary)
        Dim Schema As DatabaseSchema = DatabaseSchema.Compile
        Dim FileName As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "ToDo Database")
        Dim Database As CsvDatabase = CsvDatabase.Connect(FileName, Schema, True)

        ' Show the form that maintains the Task table
        WindowGenerator.GenerateListWindow(Database, Schema("Task")).ShowDialog()

    End Sub

End Module
